VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsProveedores"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Dim vSQL As String

Public pNumError As Long
Public pDesError As String
Public pCanReg As Long
Public pRS As ADODB.Recordset
Public pIdDevuelto As Long

Private vIdProveedor As Long

Public Property Let idProveedor(ByVal VData As Long)
    vIdProveedor = VData
End Property
Public Property Get idProveedor() As Long
    idProveedor = vIdProveedor
End Property

Private Sub AsignarValores(Optional ByVal rs As ADODB.Recordset, Optional pNoAsigRs As Boolean)
    If Not pNoAsigRs Then
        Set Me.pRS = rs
    End If
    Me.pCanReg = objCnxAeros.pCanReg
    Me.pDesError = objCnxAeros.pDesError
    Me.pIdDevuelto = objCnxAeros.pUltIdenOtor
    Me.pNumError = objCnxAeros.pNumError
End Sub

Public Function ActualizarProveedor_by_ID(ByVal ID_Proveedor As Long, ByVal razon_social As String, _
                                    ByVal telefono As String, ByVal direccion As String, _
                                    ByVal mail As String, ByVal web As String, ByVal cuit As String, _
                                    ByVal fax As String, ByVal celular As String, ByVal id_localidad As Long) As Boolean
Dim strSQL As String

   'Atualizar proveedor by ID
    strSQL = " UPDATE proveedores SET razon_social='" & razon_social & _
                                        "',telefono='" & telefono & _
                                        "',direccion='" & direccion & _
                                        "',mail='" & mail & _
                                        "',web='" & web & _
                                        "',cuit='" & cuit & _
                                        "',fax='" & fax & _
                                        "',celular='" & celular & _
                                        "',id_localidad =" & id_localidad & _
                                        " WHERE proveedores.id_proveedor =" & ID_Proveedor
                                        
    If objCnxAeros.EjecutarComando(strSQL) Then
        ActualizarProveedor_by_ID = True
    Else
        ActualizarProveedor_by_ID = False
    End If

End Function

Public Function BorrarProveedor_by_ID(ByVal id As Long)
Dim strSQL As String

    'Atualizar proveedor by ID
    strSQL = " UPDATE proveedores SET fecha_baja ='" & Date & "'" & _
             " WHERE proveedores.id_proveedor =" & id

    If objCnxAeros.EjecutarComando(strSQL) Then
        BorrarProveedor_by_ID = True
    Else
        BorrarProveedor_by_ID = False
    End If

End Function

Public Function sel_Provincias()
Dim rs As New ADODB.Recordset
Dim strSQL As String
    strSQL = "SELECT id_provincia, provincia From provincias"
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs
    
End Function

Public Function sel_Localidades(ByVal id_provincia As Integer)
Dim rs As New ADODB.Recordset
Dim strSQL As String
    strSQL = "SELECT id_Localidad, localidad From localidades WHERE id_Provincia=" & id_provincia
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function sel_Proveedores()
Dim rs As New ADODB.Recordset
Dim strSQL As String
    strSQL = "SELECT id_proveedor, razon_social From Proveedores WHERE fecha_baja is null ORDER BY razon_social "
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function GrabarProveedor(ByVal razon_social As String, _
                                    ByVal telefono As String, ByVal direccion As String, _
                                    ByVal mail As String, ByVal web As String, ByVal cuit As String, _
                                    ByVal fax As String, ByVal celular As String, ByVal id_localidad As Long) As Boolean
Dim strSQL As String

 
    'agregar nuevo proveedor

    strSQL = " INSERT INTO proveedores (razon_social,telefono,direccion,mail,web,cuit,fax,celular,id_localidad) values (" & _
                                        "'" & razon_social & _
                                        "','" & telefono & _
                                        "','" & direccion & _
                                        "','" & mail & _
                                        "','" & web & _
                                        "','" & cuit & _
                                        "','" & fax & _
                                        "','" & celular & _
                                        "'," & id_localidad & ")"
                                      
                                        
    If objCnxAeros.EjecutarComando(strSQL) Then
        GrabarProveedor = True
    Else
        GrabarProveedor = False
    End If
    AsignarValores , True

End Function

Public Function cargarProveedor_by_ID(ByVal id As Long)
Dim rs As New ADODB.Recordset
Dim strSQL As String

   'Cargar proveedor by ID
   strSQL = " SELECT p.id_proveedor, p.razon_social, p.telefono, p.direccion, p.mail, p.web, " & _
            " p.cuit, p.fax, p.celular, p.id_localidad, p.notas, " & _
            " p.fecha_baja, p.motivo_baja, loc.id_provincia " & _
            " FROM proveedores p, localidades loc, provincias prov " & _
            " WHERE prov.id_provincia = loc.id_provincia AND p.id_localidad = loc.id_localidad " & _
            " AND p.id_proveedor = " & id
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
        
    AsignarValores rs
    
End Function

Public Sub sel_ArticulosdeUnProveedor(ByVal pid_proveedor As Long)
Dim strSQL As String
Dim rs As New ADODB.Recordset

    strSQL = "SELECT id_proveedor, id_articulo " & _
                "FROM ARTICULOS_X_PROVEEDOR " & _
                "WHERE id_proveedor = " & pid_proveedor
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Sub

Public Function del_ArticulosDeUnProveedor(ByVal pid_proveedor As Long) As Boolean
Dim strSQL As String

    strSQL = "DELETE FROM ARTICULOS_X_PROVEEDOR WHERE id_proveedor = " & pid_proveedor
    If objCnxAeros.EjecutarComando(strSQL) Then
        del_ArticulosDeUnProveedor = True
    Else
        del_ArticulosDeUnProveedor = False
    End If

End Function




